package JFrame;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import DAO.PurchaseImpl;

public class Purchase extends JPanel {
	private static final long serialVersionUID = -6038402709001455579L;
	JButton bt1,bt3,bt4,home;
	JLabel lb1,bg;
	JTextArea ta;
	public Purchase() {
		ImageIcon img1 = new ImageIcon(HomePage.class.getResource("add.png"));
		//ImageIcon img2 = new ImageIcon(HomePage.class.getResource("modify.png"));
		ImageIcon img3 = new ImageIcon(HomePage.class.getResource("delete.png"));
		ImageIcon img4 = new ImageIcon(HomePage.class.getResource("update.png"));
		ImageIcon img5 = new ImageIcon(HomePage.class.getResource("2.png"));
		ImageIcon home1 = new ImageIcon(HomePage.class.getResource("back.png"));
		ImageIcon bg1 = new ImageIcon(HomePage.class.getResource("userbg.jpg"));
		
		bt1 = new JButton(img1);
		//bt2 = new JButton(img2);
		bt3 = new JButton(img3);
		bt4 = new JButton(img4);
		lb1= new JLabel(img5);
		ta = new JTextArea();
		home = new JButton(home1);
		bg = new JLabel(bg1);
		
		this.setLayout(null); // 绝对布局
		home.setBounds(1, 1, 64, 64);
		bt1.setBounds(320, 50, 30, 30);
		//bt2.setBounds(360, 50, 30, 30);
		bt3.setBounds(360, 50, 30, 30);
		bt4.setBounds(400, 50, 30, 30);
		lb1.setBounds(150, 90, 500,300);
		ta.setBounds(220, 220, 400, 400);
		bg.setBounds(0, 0, 800, 600);
		//字体
		Font font = new Font("幼圆", Font.BOLD, 20); // 字体
		ta.setForeground(Color.black);
		ta.setFont(font);
		ta.setText(queryAll());//显示所有商品信息
		ta.setBackground(null);//隐藏边框
		this.add(bt1);
		//this.add(bt2);
		this.add(bt3);
		this.add(bt4);
		this.add(lb1);
		this.add(ta);
		this.add(home);
		this.add(bg);
		home.setOpaque(false);//按钮透明
		home.setBorderPainted(false); // 按钮无边框
		//按钮监听
		bt1.addActionListener(new B1());
		//bt2.addActionListener(new B2());
		bt3.addActionListener(new B3());
		bt4.addActionListener(new B4());
	}
	public String queryAll(){
		PurchaseImpl pdi = new PurchaseImpl();
		String s;
		s = pdi.query();
		return s;
	}
	//内部类
		class B1 implements ActionListener
		{
			public void actionPerformed(ActionEvent e){
				new purchaseAdd();
			}
		}
		class B3 implements ActionListener
		{
			public void actionPerformed(ActionEvent e){
				new purchaseDelete();
			}
		}
		class B4 implements ActionListener
		{
			public void actionPerformed(ActionEvent e){
				ta.setText(queryAll());
			}
		}
}
